package cn.mcch.investigator.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Switch;

import java.util.ArrayList;
import java.util.List;

import cn.mcch.investigator.R;
import cn.mcch.investigator.dialog.LoadingDialog;
import cn.mcch.investigator.listener.OnResponseListener;
import cn.mcch.investigator.model.impl.FindModelImpl;
import cn.mcch.investigator.model.impl.MyTaskModelImpl;
import cn.mcch.investigator.presenter.impl.FindPresenterImpl;
import cn.mcch.investigator.presenter.impl.MyTaskPresenterImpl;
import cn.mcch.investigator.utils.DialogUtils;
import cn.mcch.investigator.utils.ToastUtils;
import cn.mcch.investigator.viewdelegate.impl.FindViewDelegateImpl;
import cn.mcch.investigator.viewdelegate.impl.MyTaskViewDelegateImpl;

/**
 * Created by Administrator on 2016/12/17.
 */
public class FindFragment extends BaseFragment<FindViewDelegateImpl, FindModelImpl, FindPresenterImpl> implements OnResponseListener {

    private LoadingDialog loadingDialog;

    public FindFragment() {
        super();
        isLoadData = true;
    }

    @Override
    public Class<FindPresenterImpl> getPresenterClass() {
        return FindPresenterImpl.class;
    }

    @Override
    public void createFirstView() {
        mPresenter.createFirstView(getActivity().getApplicationContext(), R.layout.fragment_find, this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sb_find:
                // 综合查询
                if (mPresenter.verifyInput()) {
                    loadingDialog = DialogUtils.showLoadingDialog(getFragmentManager(), "正在查询，请稍后...");
                    mPresenter.find(1, this);
                }
                break;
            case R.id.iv_arrow:
                // 展开或折叠综合查询案件
                mPresenter.toggle();
                break;
            default:
                break;
        }
    }

    @Override
    public void onBefore(int id) {

    }

    @Override
    public void onAfter(boolean result, int id) {
        loadingDialog.dismiss();
        loadingDialog = null;
        mPresenter.setVisibility(result);
    }

    @Override
    public void onSuccess(String json, int id) {
        switch (id) {
            case 1:
                // 综合查询成功
                mPresenter.setData(json);
                break;
            default:
                break;
        }
    }
}
